var information={};
$(function(){
	getAllFiniCom(null);
	initTaskDis();
	requestDepartment();
	requestSort();
	 //分页，首页
	  $("#headPage").click(function(){ 
		information.currentPage=1;
	  	$("#totalPage").html(information.currentPage+"/"+information.totalPage);
	  	getAllFiniCom(information);
	  })
	  
	  $(document).on("click",".detail",function(){
		  var id= $(this).attr("data-id");
			var menuId=$("#menu-container").attr("menu-id");
			window.location.href = '../information/commentDetailInfo.jsp?menuId='+menuId+'&detailId=' + id;
	  })

	  //分页，尾页
	  $("#endPage").click(function(){
	  	$("#totalPage").html(information.totalPage+"/"+information.totalPage);
	  	information.currentPage=totalPage;
	  	getAllFiniCom(information);
	  })
	  //分页，上一页
	  $("#prevPage").click(function(){
	  	if(information.currentPage<=1)
	  	{
	  		information.currentPage=1;
	  	}
	  	else
	  	{
	  		information.currentPage=information.currentPage-1;
	  		$("#totalPage").html(information.currentPage+"/"+information.totalPage);  
	  		getAllFiniCom(information);
	  	}

	 })
	 
	  //分页，下一页
	   $("#nextPage").click(function(){
	  	
	  	if(information.currentPage>=information.totalPage)
	  	{
	  		information.currentPage=information.currentPage;
	  	}
	  	else
	  	{
	  		information.currentPage=information.currentPage+1;
	  		$("#totalPage").html(information.currentPage+"/"+information.totalPage);
	  		getAllFiniCom(information);
	  	}
	  	
	  })
});
//查询向后台请求部门信息
function requestDepartment()
{	var url="getDepartmentAndArea.do";//分口地址

	var data={};
	var object={};
	data=YuXi.util.get(url,null,function(data){
		object=data.object;
	
		//用data循环添加部门信息	
		for(var i=0;i<object.length;i++)
		{
			 var html="<option  value="+object[i].id+">"+object[i].name+"</option>";
			 $(".reDepartment").append(html);
		}
		
	},function(){});//请求数据
	
}

/*获取所有已点评的信息*/
function getAllFiniCom(data){
	
//	 YuXi.util.get("getCommentRecord.do",data,function(data){
		 var url="getCommentRecord.do";
		  YuXi.util.get(url,data,function(data){	 
				object=data.list;
				information.totalPage=data.totalPage;
				information.page=data.currentPage;
				$("#totalPage").text(information.page+"/"+information.totalPage);
				$("#table1body").html("");
				for(var i=0;i<object.length;i++)
				{
					var pname= object[i].inputPerSonNames;
//				pname=pname.substring(1);
				pname=pname.substring(0,pname.length-1);
				object[i].inputPerSonNames=pname;
					if( object[i].informationProfile.length>15)
						object[i].informationProfile= object[i].informationProfile.substring(0,15)+"...";
					if(object[i].inputPerSonNames.length>10){
						object[i].inputPerSonNames=object[i].inputPerSonNames.substring(0,12)+"...";
					}
					var time=YuXi.getTime.get(object[i].createTime);
					object[i].informationSortNames=object[i].informationSortNames.substring(0,4);
					var arrdd =object[i].informationSourceNames.split(",");
						object[i].informationSourceNames=arrdd[0];
					//************************************************12.10显示一级*****************02
					var soucename=YuXi.TOPsouce.souce(object[i].informationSourceID,souceobject);
				
					object[i].informationSourceNames=soucename;
					var portname=YuXi.TOPsouce.port(object[i].safetyPortId,fenobject);

					object[i].safetyPortNames=portname;
					//************************************************12.10*****************02
					var html="<tr ><td>"+ (i+1)+"</td>"+
					
					"<td >" + object[i].safetyPortNames + "</td>" +
						"<td >" + object[i].informationSourceNames + "</td>" +
						"<td >" + object[i].informationSortNames + "</td>" +
						"<td >" + object[i].informationClassificationNames + "</td>" +
						"<td >" + object[i].informationProfile + "</td>"
						 +"<td >"+time+"</td>"+
						 "<td >"+object[i].flowName+"</td>"+"<td>" + object[i].userName + "</td>"+
					"<td><a data-id="+object[i].id+"  href='javascript:void(0);' class='detail'>详情</a>&nbsp;&nbsp;<a data-id="+object[i].id+" href='javascript:void(0);' data-id='"+object[i].id+"' data-id='"+object[i].id+"'data-account='"+object[i].informationAccount+"' class='input-task-finsh-context'>点评信息</a>&nbsp;&nbsp;</td></tr>";
					
					$("#table1body").append(html);
				}
				
		YuXi.graded.get();
		
	});
}
/*跳转到信息详情页面*/
function toComDetail(id){
	 window.location.href='commitDetail.jsp?detailId='+id;
}

function initTaskDis(){
	 YuXi.util.get("getAllInformationClassification.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".reSearchpes").append("<option value='"+obj[i].id+"' >"+obj[i].name+"</option>");
			 }
			 
		 }
	 });
	 
	 YuXi.util.get("getAllInformationPort.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".task-port").append("<option value='"+obj[i].id+"' >"+obj[i].portName+"</option>");
			 }
			 
		 }
	 });
	
}
$("#firstSearch").click(function(){
	firstSearch();
});
//简介，分级，渠道，状态，时间（今天,一周...）查找
function firstSearch()
{

		
		
		
	var information={};
	var curFlowText = $(".reSearchFlow option:selected").val();
		curFlowText == null ? "" : information.curFLow = curFlowText; //当前状态
		information.inputName=$("#requestName").val();
	if($("#profile").val()!=null&&$("#profile").val()!="")
		information.key=$("#profile").val();//简介

	information.key = $("#profile").val(); //简介
	if($("#profile").val()=="请输入简介关键字")
	{
		information.key="";
	}
	//----------------------------------------
		var fenkouID=$(".rePort option:selected").val()+",";//分口
		fenkouID+=YuXi.recursionSource.get(fenkouID,"1");
		var arrayunqiue=[];
		arrayunqiue=YuXi.recursionSource.unique(fenkouID.split(","));
		fenkouID=arrayunqiue.join(",");
		information.salfPort=fenkouID;
		//---------------------------------------
	information.structure=$(".reDepartment option:selected").val();//部门
	var inputNameFlag=$("#requestName").val();//参与人
		if(inputNameFlag=="请输入参与人/录入人姓名或警号")
		{
			information.intputName="";
			delete information.intputNumber;
		}
		else
		{ 
			var flag=/^[(-?\d+\.\d+)|(-?\d+)|(-?\.\d+)]+$/.test(inputNameFlag + '');
			
			if(!flag)
			{
				information.intputName=inputNameFlag;
				
				delete information.intputNumber;
			}
			else 
			{
				
				delete information.intputName;
				information.intputNumber=inputNameFlag;

			}
		}
	//******************************************************12.10搜索************************04
		try{
			information.informationSource =$(".reSearchSource").select2('val').join(",");
			
		}
		catch(e){
			information.informationSource="null";
		}
		//******************************************************12.10************************04
	if($(".pes option:selected").val()!="null"&&$(".pes option:selected").val()!="")
		information.informationLv=$(".pes option:selected").val();//分级
	if($(".reSearchsort option:selected").val()!="null"&&$(".reSearchsort option:selected").val()!="")
		information.informationSort=$(".reSearchsort option:selected").val();//分类
	//var value=$(".valTime option:selected").val();
	var array=[];	
	var starTime=$("#starTime").val();
	var endTime=$("#endTime").val();
	array=YuXi.timestamp.get(starTime,endTime,null);	
	if(array[0]!=null)
		information.startTimestamp = array[0];
	if(array[1]!=null)
		information.endTimestamp = array[1];

	information.currentPage=1;
		

	getAllFiniCom(information);
	
	
}

//向后台请求分类信息
function requestSort(){	
	var url="getAllInfomationSort.do";//分类地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分类信息
		for(var i=0;i<object.length;i++)
		{
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".reSearchsort").append(html);
		}
	},function(){
		
	});//请求数据
	
	}